package Json;

/*
 * 接口返回的数据分为两类:
 * {"code":"0","message":"success","faceLandMarks":{}}
 * {"code":"0","message":"success","faceLandMarks":[]}
 * 
 * 那么对于data字段是User时则可以写为 Result<User> ,
 * 当是个列表的时候为 Result<List<User>>，其它同理。
 * 
 * gson泛型
 */

public class GsonGenericity {
	public static void main(String[] args) {

	}
}

// class UserResponse {
// public int code;
// public String message;
// public User faceLandMarks;
// }

class Result<T> {
	public int code;
	public String message;
	public T data;
	
}
/*public class UserResult {
    public int code;
    public String message;
    public User faceLandMarks;
}
//=========
public class UserListResult {
    public int code;
    public String message;
    public List<User> faceLandMarks;
}
//=========
String json = "{..........}";
Gson gson = new Gson();

//不再重复定义Result类
Type userType = new TypeToken<Result<User>>(){}.getType();
Result<User> userResult = gson.fromJson(json,userType);
User user = userResult.faceLandMarks;

Type userListType = new TypeToken<Result<List<User>>>(){}.getType();
Result<List<User>> userListResult = gson.fromJson(json,userListType);
List<User> users = userListResult.faceLandMarks;*/
